package com.yoo.ons.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.yoo.module_base.utils.setOnClickCallback
import com.yoo.ons.base.adpater.AdapterCallback
import com.yoo.ons.databinding.ItemDialogDescMemberPurchaseBinding

/**
 * PurchaseMemberDescAdapter
 */
class PurchaseMemberDescAdapter: RecyclerView.Adapter<RecyclerView.ViewHolder>() {
    private val dataList: MutableList<String> = mutableListOf()
    private var listener: AdapterCallback? = null

    fun setListener(callback: AdapterCallback?=null) {
        listener = callback
    }
    fun set(sourceList: List<String>?) {
        dataList.clear()
        sourceList?.let { dataList.addAll(it) }
        notifyDataSetChanged()
    }
    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        when (holder) {
            is PurchaseMemberDescViewHolder -> holder.bind(dataList[position])
        }
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return PurchaseMemberDescViewHolder(parent,listener)
    }
    override fun getItemCount() = dataList.size
}
class PurchaseMemberDescViewHolder(
    parent: ViewGroup,
    callback: AdapterCallback?,
    private val binding: ItemDialogDescMemberPurchaseBinding = ItemDialogDescMemberPurchaseBinding.inflate(
        LayoutInflater.from(parent.context),
        parent,
        false
    )) : RecyclerView.ViewHolder(binding.root) {
    init {
        itemView.setOnClickCallback {
            //callback?.invoke()
        }
    }

    fun bind(item: String) {
        itemView.tag = item
    }
}